import  mediaquery  from "@ohos.mediaquery";

export default class BreakPointSystem{
  private smListener:mediaquery.MediaQueryListener=mediaquery.matchMediaSync('sm')
  private mdListener:mediaquery.MediaQueryListener=mediaquery.matchMediaSync('md')
  private lgListener:mediaquery.MediaQueryListener=mediaquery.matchMediaSync('lg')

  smListenerCallback(result:mediaquery.MediaQueryResult){
    if(result.matches){
      AppStorage.setOrCreate('currentBreakpoint','sm')

    }

  }
  mdListenerCallback(result:mediaquery.MediaQueryResult){
    if(result.matches){
      AppStorage.setOrCreate('currentBreakpoint','md')

    }

  }
  lgListenerCallback(result:mediaquery.MediaQueryResult){
    if(result.matches){
      AppStorage.setOrCreate('currentBreakpoint','lg')

    }

  }
  updateCurrentBreakpoint(breakpoint:string){
    AppStorage.setOrCreate('currentBreakpoint',breakpoint)

  }
  register(){
    this.smListener.on('change',this.smListenerCallback.bind(this))
    this.mdListener.on('change',this.mdListenerCallback.bind(this))
    this.lgListener.on('change',this.lgListenerCallback.bind(this))

  }
  unregister(){
    this.smListener.off('change',this.smListenerCallback.bind(this))
    this.mdListener.off('change',this.mdListenerCallback.bind(this))
    this.lgListener.off('change',this.lgListenerCallback.bind(this))

  }


}